/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.bishe.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.bishe.entity.BisheGoodsLog;
import com.thinkgem.jeesite.modules.bishe.service.BisheGoodsLogService;

/**
 * 物品日志管理Controller
 * @author yue
 * @version 2018-12-28
 */
@Controller
@RequestMapping(value = "${adminPath}/bishe/bisheGoodsLog")
public class BisheGoodsLogController extends BaseController {

	@Autowired
	private BisheGoodsLogService bisheGoodsLogService;
	
	@ModelAttribute
	public BisheGoodsLog get(@RequestParam(required=false) String id) {
		BisheGoodsLog entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bisheGoodsLogService.get(id);
		}
		if (entity == null){
			entity = new BisheGoodsLog();
		}
		return entity;
	}
	
	@RequiresPermissions("bishe:bisheGoodsLog:view")
	@RequestMapping(value = {"list", ""})
	public String list(BisheGoodsLog bisheGoodsLog, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BisheGoodsLog> page = bisheGoodsLogService.findPage(new Page<BisheGoodsLog>(request, response), bisheGoodsLog); 
		model.addAttribute("page", page);
		return "modules/bishe/bisheGoodsLogList";
	}

	@RequiresPermissions("bishe:bisheGoodsLog:view")
	@RequestMapping(value = "form")
	public String form(BisheGoodsLog bisheGoodsLog, Model model) {
		model.addAttribute("bisheGoodsLog", bisheGoodsLog);
		return "modules/bishe/bisheGoodsLogForm";
	}

	@RequiresPermissions("bishe:bisheGoodsLog:edit")
	@RequestMapping(value = "save")
	public String save(BisheGoodsLog bisheGoodsLog, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bisheGoodsLog)){
			return form(bisheGoodsLog, model);
		}
		bisheGoodsLogService.save(bisheGoodsLog);
		addMessage(redirectAttributes, "保存物品日志信息成功");
		return "redirect:"+Global.getAdminPath()+"/bishe/bisheGoodsLog/?repage";
	}
	
	@RequiresPermissions("bishe:bisheGoodsLog:edit")
	@RequestMapping(value = "delete")
	public String delete(BisheGoodsLog bisheGoodsLog, RedirectAttributes redirectAttributes) {
		bisheGoodsLogService.delete(bisheGoodsLog);
		addMessage(redirectAttributes, "删除物品日志信息成功");
		return "redirect:"+Global.getAdminPath()+"/bishe/bisheGoodsLog/?repage";
	}

}